package com.jblog.core.service.facde.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jblog.common.page.Pagination;
import com.jblog.core.model.blog.Category;
import com.jblog.core.model.blog.Comment;
import com.jblog.core.model.blog.Post;
import com.jblog.core.model.blog.Tag;
import com.jblog.core.model.blog.archive.PostCalendarArchive;
import com.jblog.core.model.blog.param.CategoryParam;
import com.jblog.core.model.blog.param.CommentParam;
import com.jblog.core.model.blog.param.PostParam;
import com.jblog.core.model.blog.param.TagParam;
import com.jblog.core.service.blog.ArchiveService;
import com.jblog.core.service.blog.CategoryService;
import com.jblog.core.service.blog.CommentService;
import com.jblog.core.service.blog.PostService;
import com.jblog.core.service.blog.TagService;
import com.jblog.core.service.facde.BlogFacade;

@Service
public class BlogFacadeImpl implements BlogFacade {

    /**** Post Service ****/
    @Autowired private PostService postService;

    @Override
    public Post findPostById(Long id) {
        return postService.findById(id);
    }
    
    public Post findPostByAlisa(String alias) {
        return postService.findByAlisa(alias);
    }
    
    @Override
    public List<Post> findPostByParam(PostParam p) {
        return postService.findByParam(p);
    }
    
    @Override
    public Pagination findPostByParamByPage(PostParam p) {
        return postService.findByParamByPage(p);
    }

    @Override
    public List<Post> findPreviousAndNextOfPost(PostParam p) {
        return postService.findPreviousAndNext(p);
    }

    @Override
    public Long findCountOfPost(PostParam p) {
        return postService.count(p);
    }

    @Override
    public Long findMaxIdOfPost() {
        return postService.findMaxId();
    }

    @Override
    public void savePost(Post e) {
        postService.save(e);
    }

    @Override
    public void updatePost(Post e) {
        postService.update(e);
    }

    @Override
    public void enDisablePost(Post e, boolean able) {
        postService.enDisable(e, able);
    }

    @Override
    public void deletePost(Long id) {
       postService.delete(id);
    }

    
    /**** Tag Service ****/
    @Autowired private TagService tagService;
    
    @Override
    public Tag findTagById(Long id) {
        return tagService.findById(id);
    }
    
    @Override
    public List<Tag> findTagByPostId(Long id) {
        return tagService.findByPostId(id);
    }
    
    @Override
    public Tag findTagByAlisa(String s) {
        return tagService.findByAlisa(s);
    }
    
    @Override
    public List<Tag> findTagByParamByPage(TagParam p) {
        return tagService.findByParam(p);
    }

    @Override
    public Long findCountOfTag(TagParam p) {
        return tagService.count(p);
    }

    @Override
    public void enDisableTag(Tag e, boolean able) {
        tagService.enDisable(e, able);
    }

    @Override
    public void saveTag(Tag e) {
        tagService.save(e);
    }

    @Override
    public void updateTag(Tag e) {
        tagService.update(e);
    }

    @Override
    public void deleteTag(Long id) {
        tagService.delete(id);
    }
    
    /**** Category Service ****/
    @Autowired private CategoryService categoryService;

    @Override
    public Category findCategoryById(Long id) {
        return categoryService.findById(id);
    }

    @Override
    public Category findCategoryByAlisa(String s) {
        return categoryService.findByAlisa(s);
    }

    @Override
    public List<Category> findCategoryByParamByPage(CategoryParam p) {
        return categoryService.findByParam(p);
    }

    @Override
    public List<Category> findAllCategory(CategoryParam p) {
        return categoryService.findAll(p);
    }

    @Override
    public void enDisableCategory(Category e, boolean able) {
        categoryService.enDisable(e, able);
    }

    @Override
    public void saveCategory(Category e) {
        categoryService.save(e);
    }

    @Override
    public void updateCategory(Category e) {
        categoryService.update(e);
    }

    @Override
    public void deleteCategory(Long id) {
        categoryService.delete(id);
    }
    
    /**** Tag Service ****/
    @Autowired private CommentService commentService;

    @Override
    public Comment findCommentById(Long id) {
        return commentService.findById(id);
    }

    @Override
    public List<Comment> findCommentByPostId(Long id) {
        return commentService.findByPostId(id);
    }

    @Override
    public List<Comment> findCommentByParam(CommentParam p) {
        return commentService.findByParam(p);
    }

    @Override
    public Pagination findCommentByParamByPage(CommentParam p) {
        return commentService.findByParamByPage(p);
    }

    @Override
    public Long findCountOfComment(CommentParam p) {
        return commentService.count(p);
    }

    @Override
    public void enDisableComment(Comment e, boolean able) {
        commentService.enDisable(e, able);
    }

    @Override
    public void saveComment(Comment e) {
        commentService.save(e);
    }

    @Override
    public void updateComment(Comment e) {
        commentService.update(e);
    }
    
    /**** ArchiveService ****/
    @Autowired private ArchiveService archiveService;
    public List<PostCalendarArchive> findCalendarArchiveOfPost() {
        return archiveService.findCalendarArchiveOfPost();
    }
    
}
